package ch.fhnw.qualiscan.application.modals;

import ch.fhnw.qualiscan.Config;
import ch.fhnw.qualiscan.application.models.QuestionnaireModel;
import ch.fhnw.qualiscan.application.views.AdminPanelView;
import ch.fhnw.qualiscan.core.Modal;
import ch.fhnw.qualiscan.core.View;
import ch.fhnw.qualiscan.core.db.pojos.Questionnaire;
import ch.fhnw.qualiscan.core.libraries.NotificationLibrary;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.HorizontalLayout;
import eu.livotov.tpt.i18n.TM;

@SuppressWarnings("serial")
public class DeleteQuestionnaire extends Modal {

    QuestionnaireModel qModel = new QuestionnaireModel();
    View view;
    
    public DeleteQuestionnaire(final Questionnaire questionnaire, final View view) {
        
        this.view = view;
        
        setCaption(TM.get("questionnaire.delete.title", questionnaire.getTitle()));
        addComponent(textHelper.p(TM.get("questionnaire.delete.desc", questionnaire.getTitle())));
        addComponent(textHelper.p(TM.get("questionnaire.delete.consequences")));

        HorizontalLayout buttonWrap = new HorizontalLayout();
        buttonWrap.setSpacing(true);
        buttonWrap.setMargin(true, false, false, false);

        Button cancelButton = new Button(TM.get("action.cancel"));
        cancelButton.setIcon(Config.ICON_CANCEL);
        cancelButton.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                    closeModal();
            }
        });

        Button deleteButton = new Button(TM.get("action.delete"));
        deleteButton.setIcon(Config.ICON_DELETE);
        deleteButton.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                qModel.removeQuestionnaire(questionnaire);
                NotificationLibrary.showSuccess(TM.get("questionnaire.deleted"), null);
                
                view.reBuild();
                closeModal();
            }
        });

        buttonWrap.addComponent(deleteButton);
        buttonWrap.addComponent(cancelButton);

        addComponent(buttonWrap);
    }
	
}
